Weekly Assignment

Interface and Application Programming

Individual Assignment
 Write an application that interfaces a user with an input and/or output device that you made
Group Assignment
 Compare as many tool options as possible.

Individual Assignment

In my final project i have to do show the drip monitoring in web and blynk so here i have Created a web interface with NodeMCU ESP8266 and blynk app

  • Web interfacing

  • Blynk App

Bylnk
 Most popular Internet of Things platform with free Cloud, iOS and Android mobile apps, Web dashboard, and Machine Learning. The website is https://blynk.io/
 There are three major components in the platform:
Blynk App - allows to you create amazing interfaces for your projects using various widgets we provide. Blynk Server - responsible for all the communications between the smartphone and hardware. You can use our Blynk Cloud or run your private Blynk server locally.
Blynk Server - responsible for all the communications between the smartphone and hardware. You can use our Blynk Cloud or run your private Blynk server locally. It’s open-source, could easily handle thousands of devices and can even be launched on a Raspberry Pi.
Blynk Libraries - for all the popular hardware platforms - enable communication with the server and process all the incoming and outcoming commands.
 Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, vizualize it and do many other cool things.
Blynk App -Features
 Similar API & UI for all supported hardware & devices
 Connection to the cloud using:
 WiFi
 Bluetooth and BLE
 Ethernet
 USB (Serial)
 GSM

  • Set of easy-to-use Widgets

  • Direct pin manipulation with no code writing

  • Easy to integrate and add new functionality using virtual pins

  • History data monitoring via SuperChart widget

  • Device-to-Device communication using Bridge Widget

  • Sending emails, tweets, push notifications, etc.

In my final project IOT based drip monitoring i have designed PCB for nodemcu esp8266 with its input photo transistor output as oled,Lodcell.i have integrated interfacing blynk and web in nodemcu esp8266

The best way to describe Blynk is that it's a IoT (internet of things) platform designed to connect deviced to the internet using user-designed smartphone apps. Below i'll try to explain briefly how I connected Blynk to control my Servo (from previous assignment).

Connecting and Arduino with a Blynk app requires 3 main steps:  

  1. Deigning Blynk app 
  2.  writing the Arduino Code with Blynk controls
  3.  Using Terminal to send/receive data to Arduino via wifi and USB

The first step is to create a new project in the Blynk App installed in my phone.
         Simply following this procedure will allow users to create new project.:
New Project >> Input Project Name>>Choose Device>>Connection Type

The The Token will be sent automatically via email after creation of project.

Adding Widgets The second step is to add widgets to the interface.

For output display of liquid i.e value display output pin is V2 for for millilitres For output display for drip i.e labeled value setting pin is V1 for drip count

blynk libaray i have been download from the girhub
https://github.com/blynkkk/blynk-library/blob/master/src/BlynkSimpleEsp8266.h
ad the following is the code

IOT based IV Dripmonitoring
#include<ESP8266WiFi.h>
#include<WiFiClient.h> #include<ESP8266WebServer.h> #include <Wire.h> #include <Servo.h> //#define BLYNK_PRINT Serial #include <BlynkSimpleEsp8266.h> #include "SH1106.h" #include "HX711.h" #define DOUT D5 #define CLK D6 HX711 scale(DOUT, CLK); int time1=0; float weight=0.0; float calibration_factor = 419640; //dripsensor int a = 0; int count=0; int laserpin = D4; int drip=0; //oled #define OLED_RESET -1 SH1106 display(0x3c, D2, D1); //servo Servo servo_1; // Giving name to servo. //website-wifi String page = ""; const char* ssid="fab-stpi-2.4"; const char* password = "coolship738"; ESP8266WebServer server(80); // Variable to store the HTTP request int ml=0; int count2=0; int l_value=0; int c_value=0; int c_state=0; int l_state=0; char auth[ ] = "BdX-PVzIew-D3wCstVJGQUchd8T5iyty"; // Your WiFi credentials. // Set password to "" for open networks. char ssid1[ ] = "fab-stpi-2.4"; char pass1[ ] = "coolship738"; void setup() { ESP.wdtEnable(65535); Blynk.begin(auth, ssid1, pass1); pinMode (laserpin,OUTPUT); pinMode(A0,INPUT); Serial.begin(115200); digitalWrite(laserpin,HIGH); //scale.set_scale(); //scale.tare(); //BUZZER & LED pinMode (D7,OUTPUT); pinMode (D8,OUTPUT); digitalWrite (D7,LOW); digitalWrite (D8,LOW); //Servo servo_1.attach(D3); // Attaching Servo to D3 servo_1.write (120); // Servo will move to 45 degree angle. //OLED display.init(); display.flipScreenVertically(); //WIFI Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); display.println("WiFi connecting... "); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", []() { page = "<html><head><title>IOT based IV Dripmonitoring </title>"; page += "</head><style type=\"text/css\">table {border-collapse: collapse;"; page += "}table, th, td {border: 1px solid black;font-size: larger;"; page += "text-align:center;}</style><body><center><h1>FABLAB,STPI-Bhubaneswar"; page += "Design</h1><h3>IOT BASED IV Drip MONITORING</h3><br>"; //page += "<h5>Name Of Patient:-</h5><br>"; //page += "<h5>Hospital bed no:-101</h5><br>"; page += "</h1><h3>DRIP FACTOR = 20</h3><br>"; page += "<table style=\"width: 600px;height: 250px;\"><tr><th>IV DRIP</th"; page += "><th> DRIP COUNT</th></tr><tr><td>TOTAL</td><td>" + String(drip) + "</td></tr><tr>"; page += "<table style=\"width: 600px;height: 250px;\"><tr><th> volume</th"; page += "><th>IV Amount</th></tr><tr><td>ml</td><td>" + String(ml) + "</td></tr><tr>"; page += "<meta http-equiv=\"refresh\" content=\"5\">"; server.send(200, "text/html", page); }); server.begin(); Serial.println("HTTP server started"); weight_sense(); ml=weight*1000; Serial.print(ml); } void loop() { int x ; x=analogRead(A0); if (x>=75 && a==0) { a=1; } else if (x<75 && a==1) { a=0; drip++; } count2=drip/20; c_state=count2; if(l_state!=c_state) { ml=ml-count2; } l_state=c_state; count2=0; Serial.println(x); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(0,10, "IOT BASED DRIPMONITOR"); display.drawString(0,20, "Dripfactor = 20"); display.drawString(0,30, "Dripcount:"+String(drip)); display.drawString(0,40, "MilliLitre:"+String(ml)); display.display(); Blynk.virtualWrite(V1,drip); Blynk.virtualWrite(V2,ml); if (ml<=50) { servo_1.write (80); // Servo will move to 45 degree angle. digitalWrite (D7,HIGH); digitalWrite (D8,HIGH); } server.handleClient(); delay(1); display.clear(); Blynk.run(); } float weight_sense() { scale.set_scale(calibration_factor); weight = scale.get_units(); weight=abs(weight); return weight; }

ESP8266 Web Server with HTML Web Page

One of the greatest features ESP8266 provides is that it cannot only connect to an existing WiFi network and act as a Web Server, but it can also set up a network of its own, allowing other devices to connect directly to it and access web pages.

Web server is a place which stores, processes and delivers web pages to Web clients. Web client is nothing but a web browser on our laptops and smartphones. The communication between client and server takes place using a special protocol called Hypertext Transfer Protocol (HTTP).In this protocol, a client initiates communication by making a request for a specific web page using HTTP and the server responds with the content of that web page or an error message if unable to do so (like famous 404 Error). Pages delivered by a server are mostly HTML documents.

Above full code here in below only put required code for web application

#include<ESP8266WiFi.h>
#include<WiFiClient.h> #include<ESP8266WebServer.h> //WIFI Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); display.println("WiFi connecting... "); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); // code for HTML server.on("/", []() { page = "<html><head><title>IOT based IV Dripmonitoring </title>"; page += "</head><style type=\"text/css\">table {border-collapse: collapse;"; page += "}table, th, td {border: 1px solid black;font-size: larger;"; page += "text-align:center;}</style><body><center><h1>FABLAB,STPI-Bhubaneswar"; page += "Design</h1><h3>IOT BASED IV Drip MONITORING</h3><br>"; //page += "<h5>Name Of Patient:-</h5><br>"; //page += "<h5>Hospital bed no:-101</h5><br>"; page += "</h1><h3>DRIP FACTOR = 20</h3><br>"; page += "<table style=\"width: 600px;height: 250px;\"><tr><th>IV DRIP</th"; page += "><th> DRIP COUNT</th></tr><tr><td>TOTAL</td><td>" + String(drip) + "</td></tr><tr>"; page += "<table style=\"width: 600px;height: 250px;\"><tr><th> volume</th"; page += "><th>IV Amount</th></tr><tr><td>ml</td><td>" + String(ml) + "</td></tr><tr>"; page += "<meta http-equiv=\"refresh\" content=\"5\">"; server.send(200, "text/html", page); }); server.begin(); Serial.println("HTTP server started"); weight_sense(); ml=weight*1000; Serial.print(ml); }


Resources:-

    https://docs.blynk.cc/

    https://docs.blynk.cc/#widgets-notifications

    https://circuits4you.com/2016/12/16/esp8266-web-server-html/

    https://randomnerdtutorials.com/esp8266-web-server/